<template>
  <div class="ChildPage TablePage">
    <vb-page ref="page">
      <template #table-handle-edit="scope">
        <el-button type="text" :icon="scope.row.status === 'save'? 'el-icon-edit': 'el-icon-view'" @click="gotoDetail(scope.row.billNo)">{{ scope.row.status === 'save'? '编辑': '查看' }}</el-button>
      </template>
      <template #table-status="scope">
        <el-tag :type="scope.row.status === 'save'? 'info': 'success'">{{ scope.row.status === 'save'? '保存': '审核' }}</el-tag>
      </template>
      <template #table-addMaterial="scope">
        <el-tag :type="scope.row.addMaterial? 'success': 'info'">{{scope.row.addMaterial? "是": "否" }}</el-tag>
      </template>
    </vb-page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      stockList:[],
      materialList:[],
    }
  },
  async mounted() {
    await this.getStock()
  },
  methods: {
    gotoDetail(billNo = '') {
      let url = '/stockTake/stockTakeTaskDetail'
      if (billNo) {
        url += `?billNo=${ billNo }`
      }
      this.$router.push(url)
    },
    async getStock() {
      this.loading = true;
      try {
        let res = await this.$api.getChildDictionaryListByKeys({
          keys: ['stock', "material"]
        });
        if (!res.res) return;
        this.stockList = res.stock;
        this.materialList = res.material;
      } finally {
        this.loading = false;
      }
    },
    /**
     * 获取仓库名
     */
    getStockName(val) {
      if (this.stockList && this.stockList.length > 0) {
        for(let i = 0; i < this.stockList.length; i++) {
          if (this.stockList[i].key === val) {
            return this.stockList[i].name;
          }
        }
      }
      return '';
    },
    /**
     * 获取物料名
     */
    getMaterialName(val) {
      if (this.materialList && this.materialList.length > 0) {
        for(let i = 0; i < this.materialList.length; i++) {
          if (this.materialList[i].key === val) {
            return this.materialList[i].name;
          }
        }
      }
      return '';
    },
  }
}
</script>

<style scoped>

</style>
